A resource fork is a fork of a computer file on Apple's classic Mac OS operating system that is used to store structured data. It is one of the two forks of a file, along with the data fork, which stores data that the operating system treats as unstructured. Resource fork capability has been carried over to the modern macOS for compatibility.
A resource fork stores information in a specific form, containing details such as icon bitmaps, the shapes of windows, definitions of menus and their contents, and application code (machine code). Any file can have a resource fork, not just applications - for example, the screen position of a document window might be stored as a resource in the document's resource fork, separate from the document's contents stored in the data fork.
In classic Mac OS, resources and resource forks served several purposes:
The Macintosh file systems store metadata distinct from either the data or resource fork, such as the creation and modification timestamps, the file type and creator codes, and fork lengths.
Some files have only a resource fork. One example is a font file in the classic Mac OS. Another example is a Classic 68k application, where even the executable code is contained in resources of type 'CODE'. Later PowerPC binaries stored the executable code in the data fork.
Since resource forks were supported only on Macintosh file systems including MFS, HFS, HFS Plus, and APFS, they could not be copied to the file systems of other . The Mac BinHex and MacBinary formats were invented to encode resource and data forks into one file, for transfer between systems. A/UX supported resource forks on Unix file systems via the AppleSingle and AppleDouble formats. Starting with Mac OS X Tiger, AppleDouble was used to store resource forks on file systems such as Windows SMB shares and FAT32 volumes.
In the HFS Plus file system, settings can be made to allow other forks in addition to the data and resource forks, to create a "multi-fork" application.
As of August 7, 2002, Apple recommended that developers should not build resources into resource forks in Mach-O binaries on Mac OS X.
Within an application or other code, resources can be loaded simply using a combination of their type, ID or name, without regard to how and where they are stored in the resource fork. The client is returned a handle to the loaded resource which can then be accessed like any other heap-based data. The OS component that facilitates this is the Resource Manager. In addition to abstracting the details of the data storage from the data, the Resource Manager also arranges sets of open resource forks into a stack, with the most recently opened file on top. When trying to load a resource, it will look in the top of the stack first, (perhaps the current document's resource fork), then the next one down (the application's resource fork), then the next one (system resource forks). This arrangement is very powerful it permits local resources to override more global ones lower down so an application can provide its own icons or fonts in place of the standard system ones, for example. It also allows an application to load resources from the system using the same API as any other resource, without regard to where or how that resource is stored to the application, all resources are equally available and easy to use. The system reserves resource IDs in a certain range to help avoid resource conflicts arising from this. Resource Manager APIs allow the programmer to manipulate the stack and modify the search behaviour.
In the structure of the resource fork, there is a piece of data called a "resource map" which stores the positions of resource data items. This can be used to allow random access to resource data based on the defined IDs and names. The resource fork can be thought of as consisting of essentially three objects, the resource header, the resource map, and the resource data itself, but in fact each data type is a hierarchical structure which stores multiple items of data. The format in which the information in the resource data is stored is defined based on the types of information, which are known as "resource types." Resource data often makes references to other types of data.
Previously resource forks were accessed via the 'Resource Manager' API. This API is now deprecated.
Under the deprecated API:
File Manager APIs such as PBOpenRF() also allowed access to the raw resource fork; however, they should be used only for applications such as copying a file Apple strongly warns against using the resource fork as a "second data fork."
From the POSIX interface, the resource fork could be accessed as ''filename''/..namedfork/rsrc or as ''filename''/rsrc; the shorter form was deprecated in Mac OS X v10.4 and removed completely in Mac OS X v10.7.
Types must be 4 bytes long, so types like snd and STR actually have a space (0x20) at the end.
| Stores an alias to another file, in a resource fork of a file whose "alias" attribute bit is set |
| Defines the shape of an application alert box |
| Stores application information |
| Defines data such as a file type icon used in an application |
| Defines a color icon used in data |
| Defines a color palette used in data |
| Defines the details of a component positioned in a window |
| Stores the machine code for the program |
| Defines the shape of a monochrome cursor (8 × 8 bit square) |
| Defines a component of a window |
| Defines the shape of a dialog box for an application |
| Defines a file type handled by an application |
| Defines the contents and shape of the balloon help displayed when the cursor hovers over the file in the Finder |
| Defines an icon displayed in the Finder |
| Defines an icon displayed in the Finder |
| Defines a monochrome item used in data |
| Defines a description of a file type |
| Defines a menu and menu bar for an application |
| Defines a menu for an application. Can also be used to define menus with complex shapes such as color palettes. |
| Defines the menu items in an application |
| Stores a QuickTime movie |
| Defines a file type which the application can open |
| Stores a PICT image contained in the file |
| Stores the environment settings for an application |
| Stores a sound used in the file |
| Stores a string or hexadecimal data used in the file |
| Stores multiple strings used in the file |
| Defines style information, such as the font, color and size of text |
| Stores text |
| Describes the data format of a specific resource type, to control how ResEdit and other resource editors display resources of that type |
| Defines the version or region of use of the file |
| Defines a window for the application. Windows of an unspecified shape can also be defined. |
| Defines the shape of an application window |
AFP natively supports resource forks. Many AFP servers internally use file systems with no resource fork support and thus store resource forks in other ways instead, such as in a special file or directory or in an alternate data stream. This happens internally on the server side though, so that from the client's perspective, files on the AFP share have native resource forks.
The SMB protocol supports a file metadata system similar to Mac forks, known as alternate data streams, which macOS uses by default since Mac OS X 10.6 if supported by the SMB server. In previous versions of Mac OS X, including upgraded versions of 10.6, this feature is disabled by default, but can be enabled manually.
On volumes that do not natively support resource forks, extended attributes, or alternate data streams, such as local FAT file systems or NFSv3 network shares, macOS uses a technique called AppleDouble to store resource forks and other Mac-specific metadata. In this case, the data fork is written as a regular file, while the resource fork and metadata are written to a separate hidden file whose name is the original file name with "._" prepended. For example, "ExampleFile.psd" would contain the data fork and "._ExampleFile.psd" would contain the corresponding resource fork and metadata.
Compatibility problems can arise if Mac clients connecting to the same network share don't use the same way of storing resource forks. For example, if one client uses a protocol with native resource fork support like AFP, but another client connects via a protocol like NFSv3 that requires AppleDouble to store resource forks, the two clients may see different resource fork contents for the same file.
Another challenge is preserving resource forks when transmitting files using non-resource fork-aware applications or with certain transfer methods, including email and FTP. A number of file formats, such as MacBinary and BinHex, have been created to handle this. Command-line system tools SplitForks and FixupResourceForks allow manual flattening and merging of resource forks.
Carbon applications compiled for the Intel architecture may have byte order issues when working with resources, because most resource data is stored in big-endian byte order, as used by the 68000 and PowerPC architectures, which does not match the Intel architecture's little-endian byte order. While the operating system automatically handles these byte order differences for the overall resource fork format and for standard resource types like 'snd ' or 'moov', any resources with non-standard types must have their data byte-swapped manually to ensure consistent behavior regardless of architecture.
Until the advent of Mac OS X v10.4, the standard UNIX command-line utilities in macOS (such as cp and mv) did not respect resource forks. To copy files with resource forks, one had to use ditto or CpMac and MvMac.
The Windows NT NTFS can support forks (and so can be a file server for Mac files), the native feature providing that support is called an alternate data stream. Windows operating system features (such as the standard Summary tab in the Properties page for non-Office files) and Windows applications use them and Microsoft was developing a WinFS that has this sort of feature as basis.
Early versions of the BeOS implemented a database within the file system, which could be used in a manner analogous to a resource fork. Performance issues led to a change in later releases to a system of complex file system attributes. Under this system resources were handled in a fashion somewhat more analogous to the Mac.
AmigaOS does not use forked files. Its are internally divided into a modular structure of large pieces (Amiga Hunk) capable of storing code, data, and additional information. Similarly, data and project files have a chunk structure codified in the IFF standard. Other file types are stored similarly to other operating systems. Though not strictly a resource fork, AmigaOS stores meta data in files known as '''.info''' files. .info files can be identified by the .info extension; for example, if you save a project to a disk, two files will be saved, MyProject and MyProject.info. MyProject would be the actual project data and MyProject.info would contain the project icon, information regarding which program is needed to open the project (since there is no application binding in AmigaOS), special project options and any user comments. .info files are invisible on the Amiga's desktop (Workbench). The icon on the desktop, taken from the .info itself, is the interface metaphor through which the user interacts both with the project itself and its associated .info file. A dialog box accessible by right-clicking the icon allows the user to see and modify the metadata present in the .info file. .info files can be seen as individual files in the command-line interface or a File manager. Modern AmigaOS clones (AROS, MorphOS and AOS4) inherit the structure (complete with metadata) of the .info files of older AmigaOS versions, and can also accept standard PNG graphic files as icon bitmaps in their .info files.
NeXT operating systems NeXTSTEP and OPENSTEP, their successor, macOS, and other systems like RISC OS implemented another solution. Under these systems the resources are left in an original format, for instance, pictures are included as complete TIFF files instead of being encoded into some sort of container. These resources are then placed in a directory along with the executable code and "raw data". The directory (called a "bundle" or "application directory") is then presented to the user as the application itself. This solution provides all of the same functionality as the resource fork, but allows the resources to be easily manipulated by any application a "resource editor" (like ResEdit) is not needed. From the command-line interface, the bundle appears to be a normal directory. This approach was not an option on the classic Mac OS, since the file system (MFS) did not support separate catalog directories. When catalog file support was included in Mac OS, with the HFS filesystem, the resource fork was retained. macOS does retain the classic Resource Manager API as part of its Carbon libraries for backward compatibility. However, the resources themselves can now be stored in separate data files within the file system the Resource Manager now hides this implementation change from the client code.
|
|